From: Christian Marangi Date: Mon, 1 Dec 2025 22:57:53 +0000 (+0100) Subject: generic: move reserved_mem backports patch to generic X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22%24PHP_SELF/%22https:/collectd.org/%22%24PHP_SELF?a=commitdiff_plain;h=5c513d1f65e985a816f243775fd355a72a060a78;p=openwrt%2Fopenwrt.git generic: move reserved_mem backports patch to generic Move reserved_mem backports patch from airoha to generic dir as it will be also used by backports package based on 6.18. Link: https://github.com/openwrt/openwrt/pull/20964 Signed-off-by: Christian Marangi --- diff --git a/target/linux/airoha/patches-6.12/083-01-v6.13-resource-Add-resource-set-range-and-size-helpers.patch b/target/linux/airoha/patches-6.12/083-01-v6.13-resource-Add-resource-set-range-and-size-helpers.patch deleted file mode 100644 index 0ea3e2ab5d..0000000000 --- a/target/linux/airoha/patches-6.12/083-01-v6.13-resource-Add-resource-set-range-and-size-helpers.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 9fb6fef0fb49124291837af1da5028f79d53f98e Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= -Date: Fri, 14 Jun 2024 13:06:03 +0300 -Subject: [PATCH] resource: Add resource set range and size helpers -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Setting the end address for a resource with a given size lacks a helper and -is therefore coded manually unlike the getter side which has a helper for -resource size calculation. Also, almost all callsites that calculate the -end address for a resource also set the start address right before it like -this: - - res->start = start_addr; - res->end = res->start + size - 1; - -Add resource_set_range(res, start_addr, size) that sets the start address -and calculates the end address to simplify this often repeated fragment. - -Also add resource_set_size() for the cases where setting the start address -of the resource is not necessary but mention in its kerneldoc that -resource_set_range() is preferred when setting both addresses. - -Link: https://lore.kernel.org/r/20240614100606.15830-2-ilpo.jarvinen@linux.intel.com -Signed-off-by: Ilpo Järvinen -Signed-off-by: Bjorn Helgaas -Reviewed-by: Jonathan Cameron ---- - include/linux/ioport.h | 32 ++++++++++++++++++++++++++++++++ - 1 file changed, 32 insertions(+) - ---- a/include/linux/ioport.h -+++ b/include/linux/ioport.h -@@ -249,6 +249,38 @@ struct resource *lookup_resource(struct - int adjust_resource(struct resource *res, resource_size_t start, - resource_size_t size); - resource_size_t resource_alignment(struct resource *res); -+ -+/** -+ * resource_set_size - Calculate resource end address from size and start -+ * @res: Resource descriptor -+ * @size: Size of the resource -+ * -+ * Calculate the end address for @res based on @size. -+ * -+ * Note: The start address of @res must be set when calling this function. -+ * Prefer resource_set_range() if setting both the start address and @size. -+ */ -+static inline void resource_set_size(struct resource *res, resource_size_t size) -+{ -+ res->end = res->start + size - 1; -+} -+ -+/** -+ * resource_set_range - Set resource start and end addresses -+ * @res: Resource descriptor -+ * @start: Start address for the resource -+ * @size: Size of the resource -+ * -+ * Set @res start address and calculate the end address based on @size. -+ */ -+static inline void resource_set_range(struct resource *res, -+ resource_size_t start, -+ resource_size_t size) -+{ -+ res->start = start; -+ resource_set_size(res, size); -+} -+ - static inline resource_size_t resource_size(const struct resource *res) - { - return res->end - res->start + 1; diff --git a/target/linux/airoha/patches-6.12/083-02-v6.16-of-reserved_mem-Add-functions-to-parse-memory-region.patch b/target/linux/airoha/patches-6.12/083-02-v6.16-of-reserved_mem-Add-functions-to-parse-memory-region.patch deleted file mode 100644 index b5bbb6e723..0000000000 --- a/target/linux/airoha/patches-6.12/083-02-v6.16-of-reserved_mem-Add-functions-to-parse-memory-region.patch +++ /dev/null @@ -1,163 +0,0 @@ -From f4fcfdda2fd8834c62dcb9bfddcf1f89d190b70e Mon Sep 17 00:00:00 2001 -From: "Rob Herring (Arm)" -Date: Wed, 23 Apr 2025 14:42:13 -0500 -Subject: [PATCH] of: reserved_mem: Add functions to parse "memory-region" - -Drivers with "memory-region" properties currently have to do their own -parsing of "memory-region" properties. The result is all the drivers -have similar patterns of a call to parse "memory-region" and then get -the region's address and size. As this is a standard property, it should -have common functions for drivers to use. Add new functions to count the -number of regions and retrieve the region's address as a resource. - -Reviewed-by: Daniel Baluta -Acked-by: Arnaud Pouliquen -Link: https://lore.kernel.org/r/20250423-dt-memory-region-v2-v2-1-2fbd6ebd3c88@kernel.org -Signed-off-by: Rob Herring (Arm) ---- - drivers/of/of_reserved_mem.c | 80 +++++++++++++++++++++++++++++++++ - include/linux/of_reserved_mem.h | 26 +++++++++++ - 2 files changed, 106 insertions(+) - ---- a/drivers/of/of_reserved_mem.c -+++ b/drivers/of/of_reserved_mem.c -@@ -12,6 +12,7 @@ - #define pr_fmt(fmt) "OF: reserved mem: " fmt - - #include -+#include - #include - #include - #include -@@ -694,3 +695,82 @@ struct reserved_mem *of_reserved_mem_loo - return NULL; - } - EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); -+ -+/** -+ * of_reserved_mem_region_to_resource() - Get a reserved memory region as a resource -+ * @np: node containing 'memory-region' property -+ * @idx: index of 'memory-region' property to lookup -+ * @res: Pointer to a struct resource to fill in with reserved region -+ * -+ * This function allows drivers to lookup a node's 'memory-region' property -+ * entries by index and return a struct resource for the entry. -+ * -+ * Returns 0 on success with @res filled in. Returns -ENODEV if 'memory-region' -+ * is missing or unavailable, -EINVAL for any other error. -+ */ -+int of_reserved_mem_region_to_resource(const struct device_node *np, -+ unsigned int idx, struct resource *res) -+{ -+ struct reserved_mem *rmem; -+ -+ if (!np) -+ return -EINVAL; -+ -+ struct device_node __free(device_node) *target = of_parse_phandle(np, "memory-region", idx); -+ if (!target || !of_device_is_available(target)) -+ return -ENODEV; -+ -+ rmem = of_reserved_mem_lookup(target); -+ if (!rmem) -+ return -EINVAL; -+ -+ resource_set_range(res, rmem->base, rmem->size); -+ res->name = rmem->name; -+ return 0; -+} -+EXPORT_SYMBOL_GPL(of_reserved_mem_region_to_resource); -+ -+/** -+ * of_reserved_mem_region_to_resource_byname() - Get a reserved memory region as a resource -+ * @np: node containing 'memory-region' property -+ * @name: name of 'memory-region' property entry to lookup -+ * @res: Pointer to a struct resource to fill in with reserved region -+ * -+ * This function allows drivers to lookup a node's 'memory-region' property -+ * entries by name and return a struct resource for the entry. -+ * -+ * Returns 0 on success with @res filled in, or a negative error-code on -+ * failure. -+ */ -+int of_reserved_mem_region_to_resource_byname(const struct device_node *np, -+ const char *name, -+ struct resource *res) -+{ -+ int idx; -+ -+ if (!name) -+ return -EINVAL; -+ -+ idx = of_property_match_string(np, "memory-region-names", name); -+ if (idx < 0) -+ return idx; -+ -+ return of_reserved_mem_region_to_resource(np, idx, res); -+} -+EXPORT_SYMBOL_GPL(of_reserved_mem_region_to_resource_byname); -+ -+/** -+ * of_reserved_mem_region_count() - Return the number of 'memory-region' entries -+ * @np: node containing 'memory-region' property -+ * -+ * This function allows drivers to retrieve the number of entries for a node's -+ * 'memory-region' property. -+ * -+ * Returns the number of entries on success, or negative error code on a -+ * malformed property. -+ */ -+int of_reserved_mem_region_count(const struct device_node *np) -+{ -+ return of_count_phandle_with_args(np, "memory-region", NULL); -+} -+EXPORT_SYMBOL_GPL(of_reserved_mem_region_count); ---- a/include/linux/of_reserved_mem.h -+++ b/include/linux/of_reserved_mem.h -@@ -7,6 +7,7 @@ - - struct of_phandle_args; - struct reserved_mem_ops; -+struct resource; - - struct reserved_mem { - const char *name; -@@ -39,6 +40,12 @@ int of_reserved_mem_device_init_by_name( - void of_reserved_mem_device_release(struct device *dev); - - struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); -+int of_reserved_mem_region_to_resource(const struct device_node *np, -+ unsigned int idx, struct resource *res); -+int of_reserved_mem_region_to_resource_byname(const struct device_node *np, -+ const char *name, struct resource *res); -+int of_reserved_mem_region_count(const struct device_node *np); -+ - #else - - #define RESERVEDMEM_OF_DECLARE(name, compat, init) \ -@@ -63,6 +70,25 @@ static inline struct reserved_mem *of_re - { - return NULL; - } -+ -+static inline int of_reserved_mem_region_to_resource(const struct device_node *np, -+ unsigned int idx, -+ struct resource *res) -+{ -+ return -ENOSYS; -+} -+ -+static inline int of_reserved_mem_region_to_resource_byname(const struct device_node *np, -+ const char *name, -+ struct resource *res) -+{ -+ return -ENOSYS; -+} -+ -+static inline int of_reserved_mem_region_count(const struct device_node *np) -+{ -+ return 0; -+} - #endif - - /** diff --git a/target/linux/generic/backport-6.12/204-v6.13-resource-Add-resource-set-range-and-size-helpers.patch b/target/linux/generic/backport-6.12/204-v6.13-resource-Add-resource-set-range-and-size-helpers.patch new file mode 100644 index 0000000000..0ea3e2ab5d --- /dev/null +++ b/target/linux/generic/backport-6.12/204-v6.13-resource-Add-resource-set-range-and-size-helpers.patch @@ -0,0 +1,73 @@ +From 9fb6fef0fb49124291837af1da5028f79d53f98e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= +Date: Fri, 14 Jun 2024 13:06:03 +0300 +Subject: [PATCH] resource: Add resource set range and size helpers +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Setting the end address for a resource with a given size lacks a helper and +is therefore coded manually unlike the getter side which has a helper for +resource size calculation. Also, almost all callsites that calculate the +end address for a resource also set the start address right before it like +this: + + res->start = start_addr; + res->end = res->start + size - 1; + +Add resource_set_range(res, start_addr, size) that sets the start address +and calculates the end address to simplify this often repeated fragment. + +Also add resource_set_size() for the cases where setting the start address +of the resource is not necessary but mention in its kerneldoc that +resource_set_range() is preferred when setting both addresses. + +Link: https://lore.kernel.org/r/20240614100606.15830-2-ilpo.jarvinen@linux.intel.com +Signed-off-by: Ilpo Järvinen +Signed-off-by: Bjorn Helgaas +Reviewed-by: Jonathan Cameron +--- + include/linux/ioport.h | 32 ++++++++++++++++++++++++++++++++ + 1 file changed, 32 insertions(+) + +--- a/include/linux/ioport.h ++++ b/include/linux/ioport.h +@@ -249,6 +249,38 @@ struct resource *lookup_resource(struct + int adjust_resource(struct resource *res, resource_size_t start, + resource_size_t size); + resource_size_t resource_alignment(struct resource *res); ++ ++/** ++ * resource_set_size - Calculate resource end address from size and start ++ * @res: Resource descriptor ++ * @size: Size of the resource ++ * ++ * Calculate the end address for @res based on @size. ++ * ++ * Note: The start address of @res must be set when calling this function. ++ * Prefer resource_set_range() if setting both the start address and @size. ++ */ ++static inline void resource_set_size(struct resource *res, resource_size_t size) ++{ ++ res->end = res->start + size - 1; ++} ++ ++/** ++ * resource_set_range - Set resource start and end addresses ++ * @res: Resource descriptor ++ * @start: Start address for the resource ++ * @size: Size of the resource ++ * ++ * Set @res start address and calculate the end address based on @size. ++ */ ++static inline void resource_set_range(struct resource *res, ++ resource_size_t start, ++ resource_size_t size) ++{ ++ res->start = start; ++ resource_set_size(res, size); ++} ++ + static inline resource_size_t resource_size(const struct resource *res) + { + return res->end - res->start + 1; diff --git a/target/linux/generic/backport-6.12/205-v6.16-of-reserved_mem-Add-functions-to-parse-memory-region.patch b/target/linux/generic/backport-6.12/205-v6.16-of-reserved_mem-Add-functions-to-parse-memory-region.patch new file mode 100644 index 0000000000..b5bbb6e723 --- /dev/null +++ b/target/linux/generic/backport-6.12/205-v6.16-of-reserved_mem-Add-functions-to-parse-memory-region.patch @@ -0,0 +1,163 @@ +From f4fcfdda2fd8834c62dcb9bfddcf1f89d190b70e Mon Sep 17 00:00:00 2001 +From: "Rob Herring (Arm)" +Date: Wed, 23 Apr 2025 14:42:13 -0500 +Subject: [PATCH] of: reserved_mem: Add functions to parse "memory-region" + +Drivers with "memory-region" properties currently have to do their own +parsing of "memory-region" properties. The result is all the drivers +have similar patterns of a call to parse "memory-region" and then get +the region's address and size. As this is a standard property, it should +have common functions for drivers to use. Add new functions to count the +number of regions and retrieve the region's address as a resource. + +Reviewed-by: Daniel Baluta +Acked-by: Arnaud Pouliquen +Link: https://lore.kernel.org/r/20250423-dt-memory-region-v2-v2-1-2fbd6ebd3c88@kernel.org +Signed-off-by: Rob Herring (Arm) +--- + drivers/of/of_reserved_mem.c | 80 +++++++++++++++++++++++++++++++++ + include/linux/of_reserved_mem.h | 26 +++++++++++ + 2 files changed, 106 insertions(+) + +--- a/drivers/of/of_reserved_mem.c ++++ b/drivers/of/of_reserved_mem.c +@@ -12,6 +12,7 @@ + #define pr_fmt(fmt) "OF: reserved mem: " fmt + + #include ++#include + #include + #include + #include +@@ -694,3 +695,82 @@ struct reserved_mem *of_reserved_mem_loo + return NULL; + } + EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); ++ ++/** ++ * of_reserved_mem_region_to_resource() - Get a reserved memory region as a resource ++ * @np: node containing 'memory-region' property ++ * @idx: index of 'memory-region' property to lookup ++ * @res: Pointer to a struct resource to fill in with reserved region ++ * ++ * This function allows drivers to lookup a node's 'memory-region' property ++ * entries by index and return a struct resource for the entry. ++ * ++ * Returns 0 on success with @res filled in. Returns -ENODEV if 'memory-region' ++ * is missing or unavailable, -EINVAL for any other error. ++ */ ++int of_reserved_mem_region_to_resource(const struct device_node *np, ++ unsigned int idx, struct resource *res) ++{ ++ struct reserved_mem *rmem; ++ ++ if (!np) ++ return -EINVAL; ++ ++ struct device_node __free(device_node) *target = of_parse_phandle(np, "memory-region", idx); ++ if (!target || !of_device_is_available(target)) ++ return -ENODEV; ++ ++ rmem = of_reserved_mem_lookup(target); ++ if (!rmem) ++ return -EINVAL; ++ ++ resource_set_range(res, rmem->base, rmem->size); ++ res->name = rmem->name; ++ return 0; ++} ++EXPORT_SYMBOL_GPL(of_reserved_mem_region_to_resource); ++ ++/** ++ * of_reserved_mem_region_to_resource_byname() - Get a reserved memory region as a resource ++ * @np: node containing 'memory-region' property ++ * @name: name of 'memory-region' property entry to lookup ++ * @res: Pointer to a struct resource to fill in with reserved region ++ * ++ * This function allows drivers to lookup a node's 'memory-region' property ++ * entries by name and return a struct resource for the entry. ++ * ++ * Returns 0 on success with @res filled in, or a negative error-code on ++ * failure. ++ */ ++int of_reserved_mem_region_to_resource_byname(const struct device_node *np, ++ const char *name, ++ struct resource *res) ++{ ++ int idx; ++ ++ if (!name) ++ return -EINVAL; ++ ++ idx = of_property_match_string(np, "memory-region-names", name); ++ if (idx < 0) ++ return idx; ++ ++ return of_reserved_mem_region_to_resource(np, idx, res); ++} ++EXPORT_SYMBOL_GPL(of_reserved_mem_region_to_resource_byname); ++ ++/** ++ * of_reserved_mem_region_count() - Return the number of 'memory-region' entries ++ * @np: node containing 'memory-region' property ++ * ++ * This function allows drivers to retrieve the number of entries for a node's ++ * 'memory-region' property. ++ * ++ * Returns the number of entries on success, or negative error code on a ++ * malformed property. ++ */ ++int of_reserved_mem_region_count(const struct device_node *np) ++{ ++ return of_count_phandle_with_args(np, "memory-region", NULL); ++} ++EXPORT_SYMBOL_GPL(of_reserved_mem_region_count); +--- a/include/linux/of_reserved_mem.h ++++ b/include/linux/of_reserved_mem.h +@@ -7,6 +7,7 @@ + + struct of_phandle_args; + struct reserved_mem_ops; ++struct resource; + + struct reserved_mem { + const char *name; +@@ -39,6 +40,12 @@ int of_reserved_mem_device_init_by_name( + void of_reserved_mem_device_release(struct device *dev); + + struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); ++int of_reserved_mem_region_to_resource(const struct device_node *np, ++ unsigned int idx, struct resource *res); ++int of_reserved_mem_region_to_resource_byname(const struct device_node *np, ++ const char *name, struct resource *res); ++int of_reserved_mem_region_count(const struct device_node *np); ++ + #else + + #define RESERVEDMEM_OF_DECLARE(name, compat, init) \ +@@ -63,6 +70,25 @@ static inline struct reserved_mem *of_re + { + return NULL; + } ++ ++static inline int of_reserved_mem_region_to_resource(const struct device_node *np, ++ unsigned int idx, ++ struct resource *res) ++{ ++ return -ENOSYS; ++} ++ ++static inline int of_reserved_mem_region_to_resource_byname(const struct device_node *np, ++ const char *name, ++ struct resource *res) ++{ ++ return -ENOSYS; ++} ++ ++static inline int of_reserved_mem_region_count(const struct device_node *np) ++{ ++ return 0; ++} + #endif + + /**